<template>
  <view class="content">
    <view class="img-box">
      <!-- 			<image :src=" headPath + imgurl.replace('\\','') " mode="widthFix" @click="zhanshitupian"></image> -->
      <image :src="  imgurl.replace('\\','') " mode="widthFix" @click="zhanshitupian"></image>
    </view>

    <view class="enter-btn">
      <button @click="tosingename"
        v-if="info[0].contractStatus != 0&& usercardid == info[0].workerIdentityCard ">立即签约</button>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        contractType: "",
        imgurls: [],
        info: [],
        imgurl: '',
        headPath: '',
        seconds: 10,
        usercardid: '', // 登录用户的身份证 用来判断是不是自己的合同
        type: 0, // 0 表示已签约 1编辑中 2待签约
        userName: '', // 登录用户的姓名 用来判断是不是自己的合同
        isNext: false, // 默认不显示下一步 如果生成成功就才显示下一步的按钮
      }
    },
    onLoad(options) {
      // 通过合同id 来查询合同里面的信息
      this.getworkerinfo(options.id)
      // 0 表示已签约 1编辑中 2待签约
      this.type = options.type
      this.usercardid = uni.getStorageSync('userCode')
      console.log('登录用户的id为', this.usercardid);
      console.log('0 表示已签约 1编辑中 2待签约', this.type);
    },
    created() {
      this.headPath = this.path
    },
    methods: {
      zhanshitupian() {
        console.log('点击查看图片');
        // this.imgurls.push(this.imgurl.replace('\\', ''))
        console.log(this.imgurls);
        uni.previewImage({
          urls: [this.imgurl.replace('\\', '')]
        })
      },
      tosingename() {
        // console.log('-----------');
        uni.setStorageSync('workerid', this.info[0].id)
        // console.log('workerinfo',this.info);
        console.log(this.info[0].id);
        uni.redirectTo({
          url: './contractFace?id=' + this.info[0].id
        })
      },
      getimgurl() {
        uni.$post(this.path + '/contract/toPicture/' + this.contractType, this.info[0]).then(res => {
          if (res.code == 200) {
            uni.hideLoading()
            this.imgurl = res.data
            console.log('success-----3');
          } else {
            uni.hideLoading()
            uni.showToast({
              title: '合同信息获取失败,请重试',
              icon: 'none'
            })
            setTimeout(() => {
              uni.navigateBack()
              return
            }, 1500)
          }
        })
      },
      // 通过合同id 来查询合同里面的信息
      getworkerinfo(id) {
        uni.showLoading({
          title: '获取合同信息中'
        })
        uni.$get(this.path + '/contract/get/' + id).then(res => {
          if (res.code == 200) {
            this.info.push(res.data);
            console.log('点击查看的合同的用户的id为', this.info[0].id);
            if (this.info[0].contractType == 1) {
              this.contractType = '1-1'
            } else if (this.info[0].contractType == 2) {
              this.contractType = '3-1'
            } else {
              this.contractType = '2-1'
            }
            console.log('查询到的合同信息',this.info[0]);
            uni.getStorageSync('nowSubpackName',this.info[0].unitName) // 记得使用完立刻删掉
            uni.getStorageSync('nowrelativeUnitId',this.info[0].relativeUnitId) // 分包单位id 记得使用完立刻删掉
            uni.getStorageSync('nowrelativeProjectId',this.info[0].relativeProjectId) // 项目id 记得使用完立刻删掉
            console.log(this.info[0].unitName);
            console.log(this.info[0].relativeUnitId);
            console.log(this.info[0].relativeProjectId);
            // debugger
          } else {
            uni.hideLoading()
            uni.showToast({
              title: '合同信息获取失败,请重试',
              icon: 'none'
            })
            setTimeout(() => {
              uni.navigateBack()
              return
            }, 1500)
          }
        }).then(res => {
          this.getimgurl()
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    width: 750rpx;
    height: 100vh;

    .img-box {
      width: 95%;
      margin: 0 auto;

      image {
        width: 100%;
      }
    }

    .kongbai {
      width: 100%;
      height: 60rpx;
    }

    .enter-btn {
      position: fixed;
      bottom: 10px;
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;

      button {
        width: 80%;
        background-color: #2f67ff;
        height: 35px;
        line-height: 35px;
        color: white;
        font-size: 14px;
      }
    }
  }
</style>
